function DataSource() {
    let listeningQueue = [];
    let commentList = [];
    function addChangeListener(subscrib) {
        listeningQueue.push(subscrib);
    }

    function removeChangeListener(subscrib) {
        listeningQueue.splice(listeningQueue.indexOf(subscrib), 1);
    }

    function getComments() {
        return commentList;
    }
    
    function insertComment(comment) {
        commentList.push(comment);
        for(let item in listeningQueue) {
            listeningQueue[item](commentList);
        }
    }

    return {
        addChangeListener,
        removeChangeListener,
        getComments,
        insertComment
    }
}

export default DataSource();